package com.example.hospital.controller;

import com.example.hospital.common.ApiResponse;
import com.example.hospital.common.PageResponse;
import com.example.hospital.domain.dto.StatusCount;
import com.example.hospital.domain.entity.Sample;
import com.example.hospital.service.SampleService;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/samples")
public class SampleController {
    private final SampleService sampleService;
    public SampleController(SampleService sampleService) { this.sampleService = sampleService; }
    /**
     * 创建样本
     * @param sample
     * @return
     */
    @PostMapping
    public ApiResponse<Sample> create(@RequestBody Sample sample) { return ApiResponse.success(sampleService.create(sample)); }
    /**
     * 更新样本状态
     * @param id
     * @param status
     * @param remark
     * @return
     */
    @PutMapping("/{id}/status")
    public ApiResponse<Boolean> updateStatus(@PathVariable("id") Long id, @RequestParam(name = "status") Integer status, @RequestParam(name = "remark", required = false) String remark) {
        return ApiResponse.success(sampleService.updateStatus(id, status, remark));
    }
    /**
     * 获取样本列表
     * @param sampleId
     * @param orderId
     * @param sampleType
     * @param status
     * @param page
     * @param size
     * @return
     */
    @GetMapping
    public ApiResponse<PageResponse<Sample>> list(@RequestParam(name = "sampleId", required = false) Long sampleId,
                                                  @RequestParam(name = "orderId", required = false) Long orderId,
                                                  @RequestParam(name = "sampleType", required = false) String sampleType,
                                                  @RequestParam(name = "status", required = false) Integer status,
                                                  @RequestParam(name = "page", defaultValue = "1") int page,
                                                  @RequestParam(name = "size", defaultValue = "10") int size) {
        return ApiResponse.success(sampleService.list(sampleId, orderId, sampleType, status, page, size));
    }
    /**
     * 获取样本状态统计
     * @return
     */
    @GetMapping("/stats")
    public ApiResponse<java.util.List<StatusCount>> stats() { return ApiResponse.success(sampleService.stats()); }
}